
import traceback
from flask import current_app as app

from app import celery_app
from app.db.models.celery_task import CeleryTask
from app.reports.export import export_port


@celery_app.task(acks_late=True)
def report_download_task(task_id, file_type=None):
    try:
        export_port(celery_task_id=task_id, file_type=file_type)
    except Exception as e:
        CeleryTask.objects(pk=task_id).update(result__status="error")
        traceback.print_exc()
        app.logger.exception(f'资产批量导出失败: {str(e)}')
